<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>上传图片验证</title>
    <link rel="stylesheet" href="base.css">
</head>
<body>
    <label for="file">上传图片格式验证：</label>
    <input type="file" name="" id="file">
    <script>
        window.onload = function(){
            var file = document.getElementById('file');
            file.onchange = function(){
                //获取图片格式 
                var path = this.value;//C:\fakepath\林乐轩个人简历.pdf
                var parts = path.split('.');
                var result = parts.slice(-1).join(''); 
                var lower_result = result.toLowerCase();
                if(lower_result === 'jpg' || lower_result === 'png'){
                    alert('上传格式正确');
                }else{
                    alert('上传格式错误');
                }              
            }
        }
    </script>
</body>
</html>